function [t sac] = findsacs(F, i, ct)
% t         the calculated threshold
% sacs      a list of starting and end points of saccades within the given
%           trial
% F   structure with F and user data (see GUIDATA)
% i         the current trial number
% ct        a custom threshold can be used otherwise this should be
%           negative
    s=F.s{i};
    sbase=s(s<50);    % 50 deg/s is cutoff for saccades so the base is 
                        % anything below that
    if ct >= 0
        t=ct;
    else
        t=mode(sbase)+std(sbase)*F.TMULT;
    end
     clf; hold on; plot(s,'g')
    %s1=[0;s;0]; %
    d=[0;diff(s>=t);]; % Speed goes above threshold % 
    hline(t,'--g')
    e=[find(d==1) find(d==-1)];
    l=e(:,2)-e(:,1)-1;

    sac=[];
    n2=size(e,1);
    if n2 > 0
        fsac=find(l>5); % Saccades must last longer than 5 sample points
        if ~isempty(fsac)
            sac=e(fsac,:)-1; % 
        end
    end 
     vline(sac(:,1),'--r');vline(sac(:,2),'--k') 